package io.bluerain.fragment.ui;

import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import io.bluerain.fragment.R;
import io.bluerain.fragment.ui.entities.BookContent;

/**
 * Created by foredawn on 15-9-21.
 * Fragment的基本用法
 */
public class BookDetailFragment extends Fragment {

    static final String ITEM_ID = "item_id";
    private BookContent.Book book;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArguments().containsKey(ITEM_ID)) {
            book = BookContent.ITEMS_MAP.get(getArguments().getInt(ITEM_ID));
        }
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View root = inflater.inflate(R.layout.fragment_book_detail, container, false);
        if (book != null) {
            //显示
            ((TextView) root.findViewById(R.id.book_title)).setText(book.title);
            ((TextView) root.findViewById(R.id.book_desc)).setText(book.desc);

        }
        return root;
    }
}
